<?php
/* @var $this QuestionController */

$this->breadcrumbs=array(
	'Question',
);
Yii::app()->clientScript->registerCssFile(Yii::app()->request->baseUrl.'/css/form.css');
Yii::app()->clientScript->registerCssFile(Yii::app()->request->baseUrl.'/redactor/redactor.css');
Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl.'/redactor/redactor.js');
Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl.'/redactor/fontsize.js');
Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl.'/redactor/vi.js');
?>
<div class="container white-bg" id="<?php echo $this->id.'-page'?>">
   <div class="main-content">
      <div class="left">
         <?php if($model != null){?>
         <div class="question-container">
            <div class="question-content" style="margin-top: 0;">
               
                  <h1 class="title bold font-opensans"><?php echo $model->ques_title?></h1>
                  <ul>
                     <li>Người gửi: <span><?php echo $model->ques_use_name?></span></li>
                     <li>Thời gian: <span><?php echo date('H:i d/m/Y',$model->ques_date_create)?></span></li>
                  </ul>
                  <div class="clear"></div>
                  <div>
                     <?php echo $model->ques_content?>
                  </div>    
              
               
            </div>
            <div class="caption-label relative left"> 
               <em class="arrow half-arrow-down sprite absolute"></em>
               <span class="font-opensans">Trả lời</span>
            </div>
            <div class="clear"></div>
            <div class="form-faq form form-answer"  id="<?php echo Yii::app()->controller->id . '-' . Yii::app()->controller->action->id?>">
               <?php if($message != ''){
                  echo Str::notificationBox('success',$message,'Thông báo');
               }?>
               <div class="clear"></div>
               <?php $form=$this->beginWidget('CActiveForm', array(
               	'id'=>'form_send_answer',
               	'enableAjaxValidation'=>true,
                  'enableClientValidation'=>true,
               )); ?>                     
               <?php $answer = new Answer();
                  $answer->unsetAttributes();
               ?>
               <div class="row">
                  <?php echo $form->labelEx($answer, 'ans_use_name');?>
                  <?php echo $form->error($answer,'ans_use_name');?>
                  <?php echo $form->textField($answer, 'ans_use_name');?>
               </div>  
               <div class="row">
                  <?php echo $form->labelEx($answer, 'ans_use_email');?>   
                  <?php echo $form->error($answer,'ans_use_email');?>
                  <?php echo $form->textField($answer, 'ans_use_email');?>
               </div>  
               <div class="row">
                  <?php echo $form->labelEx($answer, 'ans_content');?>  
                  <?php echo $form->error($answer,'ans_content');?>
                  <?php echo $form->textArea($answer, 'ans_content',array('class' => 'redactor'));?>
               </div>                     
               <div class="row relative">
                  <?php echo CHtml::submitButton('Trả lời',array('class' => 'btn btn-success'))?>
               </div>   
               <?php $this->endWidget(); ?>
            </div> <!-- End form-answer -->
            <div class="list-answer">
               <ul>
               <?php 
                  $criteria = new CDbCriteria();
                  $criteria->offset = 0;
                  $criteria->limit = 10;
                  $criteria->order = 'ans_id DESC';
                  $criteria->addCondition('ans_ques_id ='.$id) ;
                  $list_answer = Answer::model()->findAll($criteria);
                  if(count($list_answer) > 0){
                     foreach($list_answer as $ans){?>
                        <li class="ans-item">
                           <div class="left">
                              <img src="<?php echo Yii::app()->request->baseUrl;?>/images/df-avatar.jpg" />
                           </div>
                           <div class="text">
                              <div class="bold"><?php echo $ans->ans_use_name?></div>
                              <div class="ans-content"><?php echo $ans->ans_content?></div>
                              <div class="date"><?php echo date('H:i - d/m/y', $ans->ans_date_create)?></div>
                           </div>
                        </li>
                     <?}
                  }
               ?>
               </ul>
            </div>
         </div>
       <?php }else{
         echo Str::notificationBox('error','Nội dung yêu cầu không tồn tại !','Xin lỗi');
      }?>
      </div><!-- End left-content-->
      <div class="right" style="margin: 0;">
         <div class="faq" style="margin: 0;">
            <?php
               $question = new Question();
               $criteria = new CDbCriteria();
               $criteria->offset = 0;
               $criteria->limit = 10;
               $criteria->order = 'ques_id DESC';
               $list_ques = Question::model()->findAll($criteria);
            ?>
            <div class="caption uppercase text-center relative font-opensans bold"><i class="sprite absolute icon-question"></i>Hỏi đáp gần đây</div>
            <div class="list-question">
               <ul>
                  <?php foreach($list_ques as $ques){
                     $link = $ques->linkDetail($ques->ques_id,$ques->ques_title);
                     ?>
                     <li class="question-item">
                        <span class="left dots"></span>
                        <a href="<?php echo $link?>"><?php echo $ques->ques_title?></a>
                     </li>
                  <?php }?>
               </ul>
            </div>
            <div class="clear"></div>
            <div class="send-question">
               <div class="text-center bold"><span>Gửi câu hỏi của bạn tại đây</span></div>
               
                  <div class="form-faq form" style="margin-left: 10px;" id="<?php echo Yii::app()->controller->id . '-' . Yii::app()->controller->action->id?>">
                     <?php $form=$this->beginWidget('CActiveForm', array(
                     	'id'=>'form_send_faq',
                        'action' => '/gui-cau-hoi',
                     	'enableAjaxValidation'=>false,
                        'enableClientValidation'=>false
                     )); ?>                     
                     
                     <div class="row">
                        <?php echo $form->error($question,'ques_use_name');?>
                        <?php echo $form->labelEx($question, 'ques_use_name');?>
                        <?php echo $form->textField($question, 'ques_use_name');?>
                     </div>  
                     <div class="row">
                        <?php echo $form->error($question,'ques_use_email');?>
                        <?php echo $form->labelEx($question, 'ques_use_email');?>   
                        <?php echo $form->textField($question, 'ques_use_email');?>
                     </div>  
                     <div class="row">
                        <?php echo $form->error($question,'ques_title');?>
                        <?php echo $form->labelEx($question, 'ques_title');?>  
                        <?php echo $form->textField($question, 'ques_title');?>
                     </div> 
                     <div class="row">
                        <?php echo $form->error($question,'ques_content');?>
                        <?php echo $form->labelEx($question, 'ques_content');?>  
                        <?php echo $form->textArea($question, 'ques_content');?>
                     </div>                     
                     <div class="row text-center relative">
                        <?php echo CHtml::submitButton('Gửi câu hỏi',array('id' => 'submit-faq'))?>
                     </div>   
                     <?php $this->endWidget(); ?>
                  </div> 
            </div>
         </div><!-- End faq -->
         
          <div class="focus-last-week">
            <?php
               $criteria = new CDbCriteria();
               $criteria->offset = 0;
               $criteria->limit = 10;
               $criteria->order = 'news_view DESC';
               $list_news = News::model()->findAll($criteria);
            ?>
            <div class="caption uppercase text-center relative font-opensans bold"><i class="sprite absolute icon-focus"></i>Tiêu điểm tuần qua</div>
            <div class="list-news">
               <ul>
                  <?php 
                     $news_model = new News();
                     foreach($list_news as $news){
                     $link = $news_model->linkDetail($news->news_id,$news->news_title)
                     ?>
                     <li class="news-item">
                        <span class="left dots"></span>
                        <a href="<?php echo $link?>"><?php echo $news->news_title?></a>
                     </li>
                  <?php }?>
                  
               </ul>
            </div>
         </div><!-- End focus-last-week -->
         

      </div><!-- End right-content -->
   </div>
</div>
<script>
   $(document).ready(function(){
      $(".redactor").redactor({
         lang: 'vi',
         imageUpload: '<?php echo Yii::app()->request->hostInfo;?>/redactor/scripts/image_upload.php',
         plugins: ['fontsize'],
      });
   });
</script>

